package vo;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import util.HibernateUtil;

public class ItemVendaDAO {
	public void salvarItemVenda(ItemVendaVO itemVendaVO) {

		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		session.saveOrUpdate(itemVendaVO);

		transaction.commit();

	}

	public void excluir(ItemVendaVO item) {
		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		session.delete(item);

		transaction.commit();
	}
	
	
	@SuppressWarnings("unchecked")
	public List<ItemVendaVO> consultarItens(int id) {
		List<ItemVendaVO> listaDeItens = new ArrayList<ItemVendaVO>();

		Transaction transaction = null;

		Session session = HibernateUtil.currentSession();
		transaction = session.beginTransaction();

		Criteria criteria = session.createCriteria(ItemVendaVO.class);

		criteria.add(Restrictions.eq("idvenda", id));

		listaDeItens = criteria.list();

		transaction.commit();
		return listaDeItens;
	}

}